package com.example.controller;

import com.example.service.AtomicExampleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/atomic/example")
public class AtomicExampleController {

    @Autowired
    private AtomicExampleService atomicExampleService;

    @GetMapping("/increment-parallel")
    public String incrementCounterInParallel() {
        atomicExampleService.incrementInParallel();
        return "多线程并发增加计数器操作开始";
    }

    @GetMapping("/decrement-parallel")
    public String decrementCounterInParallel() {
        atomicExampleService.decrementInParallel();
        return "多线程并发减少计数器操作开始";
    }

    @GetMapping("/counter-value")
    public String getCounterValue() {
        return "当前计数器的值: " + atomicExampleService.getCounterValue();
    }

    @GetMapping("/simulateABA")
    public String simulateABA() {
        atomicExampleService.simulateABAProblem();
        return "ABA问题模拟完成，查看日志输出。";
    }
}
